/**
 * Project hdmap
 * @author shengjialiang
 * @version v1.0
 */


#include "map_common/IEventHandler.h"

/**
 * IEventHandler implementation
 */

namespace Common
{
    IEventHandler::IEventHandler()
    {
    }

    IEventHandler::~IEventHandler()
    {
    
    }

    CEventHandlerRegister::CEventHandlerRegister()
    {

    }

    CEventHandlerRegister::~CEventHandlerRegister()
    {

    }

    bool CEventHandlerRegister::registerHandler(Common::IEventHandler* in_pRefHandler)
    {
        bool r = false;
        this->mEventHandlers.push_back(in_pRefHandler);
        return r;
    }

    bool CEventHandlerRegister::unRegisterHandler(Common::IEventHandler* in_pHandler)
    {
        bool r = false;
        std::vector<IEventHandler*>::iterator bItr = this->mEventHandlers.begin();
        std::vector<IEventHandler*>::iterator eItr = this->mEventHandlers.end();
        while (bItr != eItr)
        {
            if (*bItr == in_pHandler)
            {
                this->mEventHandlers.erase(bItr);
                r = true;
                break;
            }
            ++bItr;
        }
        return r;
    }

    void CEventHandlerRegister::notifyHandlers(Common::IEvent* in_pEvent)
    {
        std::vector<IEventHandler*>::iterator bItr = this->mEventHandlers.begin();
        std::vector<IEventHandler*>::iterator eItr = this->mEventHandlers.end();
        while (bItr != eItr)
        {
            if (*bItr)
            {
                (*bItr)->onEvent(in_pEvent);
            }
            ++bItr;
        }
    }

}